package com.hamster.crmpre.web;

import com.hamster.crmpre.config.LoginInterceptor;
import com.hamster.crmpre.pojo.dto.LineChart;
import com.hamster.crmpre.service.DataChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * 数据统计图的Controller
 * @author Tarry
 * @create 2020/2/17 13:37
 */
@RestController
@RequestMapping("dataChart")
public class DataChartController {
    @Autowired
    private DataChartService dataChartService;

    @GetMapping("personalLineChart")
    public ResponseEntity<LineChart> getPersonalLineChart(){
        String userId = LoginInterceptor.getLoginUser().getUserId();

        LineChart lineChart = null;
        try {
            lineChart = dataChartService.getPersonalLineChart(userId);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return ResponseEntity.ok(lineChart);
    }


    @GetMapping("employeeLineChart")
    public ResponseEntity<LineChart> getEmployeeLineChart(@RequestParam String employeeId){
        LineChart lineChart = null;
        try {
            lineChart = dataChartService.getPersonalLineChart(employeeId);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return ResponseEntity.ok(lineChart);
    }

}
